home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2004 April / SGI IRIX 6.5 Applications 2004 April.iso / dist / mozilla.idb / var / netscape / mozilla / chrome / messenger.jar.z / messenger.jar / content / messenger-smime / msgHdrViewSMIMEOverlay.js < prev    next >
Text File  |  2003-11-11  |  6KB  |  219 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  * The contents of this file are subject to the Netscape Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/NPL/
  6.  * 
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  * 
  12.  * 
  13.  * The Initial Developer of the Original Code is Netscape
  14.  * Communications Corporation. Portions created by Netscape are
  15.  * Copyright (C) 1998-2001 Netscape Communications Corporation. All
  16.  * Rights Reserved.
  17.  * 
  18.  * Contributors:
  19.  *   Scott MacGreogr <mscott@netscape.com>
  20.  */
  21.  
  22. var gSignedUINode = null;
  23. var gEncryptedUINode = null;
  24. var gSMIMEContainer = null;
  25. var gStatusBar = null;
  26. var gSignedStatusPanel = null;
  27. var gEncryptedStatusPanel = null;
  28.  
  29. var gEncryptedURIService = null;
  30. var gMyLastEncryptedURI = null;
  31.  
  32. // manipulates some globals from msgReadSMIMEOverlay.js
  33.  
  34. const nsICMSMessageErrors = Components.interfaces.nsICMSMessageErrors;
  35.  
  36. var smimeHeaderSink = 
  37.   maxWantedNesting: function()
  38.   {
  39.     return 1;
  40.   },
  41.  
  42.   signedStatus: function(aNestingLevel, aSignatureStatus, aSignerCert)
  43.   {
  44.     if (aNestingLevel > 1) {
  45.       // we are not interested
  46.       return;
  47.     }
  48.  
  49.     gSignatureStatus = aSignatureStatus;
  50.     gSignerCert = aSignerCert;
  51.  
  52.     gSMIMEContainer.collapsed = false;
  53.     gSignedUINode.collapsed = false;
  54.     gSignedStatusPanel.collapsed = false;
  55.   
  56.     switch (aSignatureStatus) {
  57.       case nsICMSMessageErrors.SUCCESS:
  58.         gSignedUINode.setAttribute("signed", "ok");
  59.         gStatusBar.setAttribute("signed", "ok");
  60.         break;
  61.  
  62.       case nsICMSMessageErrors.VERIFY_NOT_YET_ATTEMPTED:
  63.         gSignedUINode.setAttribute("signed", "unknown");
  64.         gStatusBar.setAttribute("signed", "unknown");
  65.         break;
  66.  
  67.       case nsICMSMessageErrors.VERIFY_CERT_WITHOUT_ADDRESS:
  68.       case nsICMSMessageErrors.VERIFY_HEADER_MISMATCH:
  69.         gSignedUINode.setAttribute("signed", "mismatch");
  70.         gStatusBar.setAttribute("signed", "mismatch");
  71.         break;
  72.  
  73.       default:
  74.         gSignedUINode.setAttribute("signed", "notok");
  75.         gStatusBar.setAttribute("signed", "notok");
  76.         break;
  77.     }
  78.   },
  79.  
  80.   encryptionStatus: function(aNestingLevel, aEncryptionStatus, aRecipientCert)
  81.   {
  82.     if (aNestingLevel > 1) {
  83.       // we are not interested
  84.       return;
  85.     }
  86.  
  87.     gEncryptionStatus = aEncryptionStatus;
  88.     gEncryptionCert = aRecipientCert;
  89.  
  90.     gSMIMEContainer.collapsed = false; 
  91.     gEncryptedUINode.collapsed = false;
  92.     gEncryptedStatusPanel.collapsed = false; 
  93.  
  94.     if (nsICMSMessageErrors.SUCCESS == aEncryptionStatus)
  95.     {
  96.       gEncryptedUINode.setAttribute("encrypted", "ok");
  97.       gStatusBar.setAttribute("encrypted", "ok");
  98.     }
  99.     else
  100.     {
  101.       gEncryptedUINode.setAttribute("encrypted", "notok");
  102.       gStatusBar.setAttribute("encrypted", "notok");
  103.     }
  104.     
  105.     if (gEncryptedURIService)
  106.     {
  107.       gMyLastEncryptedURI = GetLoadedMessage();
  108.       gEncryptedURIService.rememberEncrypted(gMyLastEncryptedURI);
  109.     }
  110.   },
  111.  
  112.   QueryInterface : function(iid)
  113.   {
  114.     if (iid.equals(Components.interfaces.nsIMsgSMIMEHeaderSink) || iid.equals(Components.interfaces.nsISupports))
  115.       return this;
  116.     throw Components.results.NS_NOINTERFACE;
  117.   }
  118. };
  119.  
  120. function forgetEncryptedURI()
  121. {
  122.   if (gMyLastEncryptedURI && gEncryptedURIService)
  123.   {
  124.     gEncryptedURIService.forgetEncrypted(gMyLastEncryptedURI);
  125.     gMyLastEncryptedURI = null;
  126.   }
  127. }
  128.  
  129. function onSMIMEStartHeaders()
  130. {
  131.   gEncryptionStatus = -1;
  132.   gSignatureStatus = -1;
  133.   
  134.   gSignerCert = null;
  135.   gEncryptionCert = null;
  136.   
  137.   gSMIMEContainer.collapsed = true;
  138.  
  139.   gSignedUINode.collapsed = true;
  140.   gSignedUINode.removeAttribute("signed");
  141.   gSignedStatusPanel.collapsed = true;
  142.   gStatusBar.removeAttribute("signed");
  143.  
  144.   gEncryptedUINode.collapsed = true;
  145.   gEncryptedUINode.removeAttribute("encrypted");
  146.   gEncryptedStatusPanel.collapsed = true; 
  147.   gStatusBar.removeAttribute("encrypted");
  148.  
  149.   forgetEncryptedURI();
  150. }
  151.  
  152. function onSMIMEEndHeaders()
  153. {}
  154.  
  155. function msgHdrViewSMIMEOnLoad(event)
  156. {
  157.   // we want to register our security header sink as an opaque nsISupports
  158.   // on the msgHdrSink used by mail.....
  159.   msgWindow.msgHeaderSink.securityInfo = smimeHeaderSink;
  160.  
  161.   gSignedUINode = document.getElementById('signedHdrIcon');
  162.   gEncryptedUINode = document.getElementById('encryptedHdrIcon');
  163.   gSMIMEContainer = document.getElementById('smimeBox');
  164.   gStatusBar = document.getElementById('status-bar');
  165.   gSignedStatusPanel = document.getElementById('signed-status');
  166.   gEncryptedStatusPanel = document.getElementById('encrypted-status');
  167.  
  168.   // add ourself to the list of message display listeners so we get notified when we are about to display a
  169.   // message.
  170.   var listener = {};
  171.   listener.onStartHeaders = onSMIMEStartHeaders;
  172.   listener.onEndHeaders = onSMIMEEndHeaders;
  173.   gMessageListeners.push(listener);
  174.  
  175.   gEncryptedURIService = 
  176.     Components.classes["@mozilla.org/messenger-smime/smime-encrypted-uris-service;1"]
  177.     .getService(Components.interfaces.nsIEncryptedSMIMEURIsService);
  178. }
  179.  
  180. function msgHdrViewSMIMEOnUnload(event)
  181. {
  182.   forgetEncryptedURI();
  183. }
  184.  
  185. function msgHdrViewSMIMEOnMessagePaneHide()
  186. {
  187.   gSMIMEContainer.collapsed = true;
  188.   gSignedUINode.collapsed = true;
  189.   gSignedStatusPanel.collapsed = true;
  190.   gEncryptedUINode.collapsed = true;
  191.   gEncryptedStatusPanel.collapsed = true; 
  192. }
  193.  
  194. function msgHdrViewSMIMEOnMessagePaneUnhide()
  195. {
  196.   if (gEncryptionStatus != -1 || gSignatureStatus != -1)
  197.   {
  198.     gSMIMEContainer.collapsed = false;
  199.  
  200.     if (gSignatureStatus != -1)
  201.     {
  202.       gSignedUINode.collapsed = false;
  203.       gSignedStatusPanel.collapsed = false;
  204.     }
  205.  
  206.     if (gEncryptionStatus != -1)
  207.     {
  208.       gEncryptedUINode.collapsed = false;
  209.       gEncryptedStatusPanel.collapsed = false;
  210.     }
  211.   }
  212. }
  213.  
  214. addEventListener('messagepane-loaded', msgHdrViewSMIMEOnLoad, true);
  215. addEventListener('messagepane-unloaded', msgHdrViewSMIMEOnUnload, true);
  216. addEventListener('messagepane-hide', msgHdrViewSMIMEOnMessagePaneHide, true);
  217. addEventListener('messagepane-unhide', msgHdrViewSMIMEOnMessagePaneUnhide, true);
  218.